home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / lpr / main.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  1KB  |  77 lines

  1. /*
  2.  * Print one or more files on a remote line printer.
  3.  *
  4.  *    lpr  [ -h host ] [ -p printer ] [ -P printer ] [ -t ] [ file ... ]
  5.  *
  6.  * If no file arguments are specified, the standard input is read.
  7.  * If any file argument is "-" it also implies the standard input.
  8.  */
  9.  
  10. #include    "defs.h"
  11.  
  12. char    *pname;
  13.  
  14. main(argc, argv)
  15. int    argc;
  16. char    *argv[];
  17. {
  18.     FILE        *fp, *fopen();
  19.     char        *s, *filename;
  20.     int        i;
  21.  
  22.     pname = argv[0];
  23.     while (--argc > 0 && (*++argv)[0] == '-')
  24.         for (s = argv[0]+1; *s != '\0'; s++)
  25.             switch (*s) {
  26.  
  27.             case 'P':        /* specify printer name */
  28.             case 'p':        /* specify printer name */
  29.                 if (--argc <= 0)
  30.                   err_quit("-%c requires another argument", *s);
  31.                 strcpy(printername, *++argv);
  32.                 break;
  33.  
  34.             case 'd':        /* debug */
  35.                 debugflag = 1;
  36.                 break;
  37.  
  38.             case 'h':        /* specify host name */
  39.                 if (--argc <= 0)
  40.                    err_quit("-h requires another argument");
  41.                 strcpy(hostname, *++argv);
  42.                 break;
  43.  
  44.             default:
  45.                 fprintf(stderr, "%s: illegal option %c\n",
  46.                             pname, *s);
  47.                 break;
  48.             }
  49.  
  50.     i = 0;
  51.     send_start();
  52.     do {
  53.         if (argc > 0) {
  54.             filename = argv[i];
  55.             if (strcmp(filename, "-") == 0) {
  56.                 fp = stdin;
  57.                 filename = "-stdin";
  58.              } else if ( (fp = fopen(argv[i], "r")) == NULL) {
  59.                 fprintf(stderr, "%s: can't open %s\n",
  60.                                 pname, argv[i]);
  61.                 continue;
  62.             }
  63.         } else {
  64.             fp = stdin;
  65.             filename = "-stdin";
  66.         }
  67.  
  68.         send_file(filename, fp);
  69.  
  70.         fclose(fp);
  71.  
  72.     } while (++i < argc);
  73.     send_done();
  74.  
  75.     exit(0);
  76. }
  77.